package net.wwang.blog.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author WangWei
 * @date 2020/8/14
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {
    public static final String VERSION = "1.0.0";

    @Bean
    public Docket portalApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(portalApiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("net.wwang.blog.controller.portal"))
                .paths(PathSelectors.any())
                .build()
                .groupName("portal");
    }

    private ApiInfo portalApiInfo() {
        return new ApiInfoBuilder()
                .title("Wangwei's blog")
                .description("门户接口服务")
                .contact(new Contact("Wangwei","http://www.wwang.net","wangwei.it@qq.com"))
                .version(VERSION)
                .build();
    }
    @Bean
    public Docket AdminApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(adminApiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("net.wwang.blog.controller.admin"))
                .paths(PathSelectors.any())
                .build()
                .groupName("admin");
    }

    private ApiInfo adminApiInfo() {
        return new ApiInfoBuilder()
                .title("Wangwei's blog")
                .description("管理员接口服务")
                .contact(new Contact("Wangwei","http://www.wwang.net","wangwei.it@qq.com"))
                .version(VERSION)
                .build();
    }

    @Bean
    public Docket UserApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(userApiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("net.wwang.blog.controller.user"))
                .paths(PathSelectors.any())
                .build()
                .groupName("user");
    }

    private ApiInfo userApiInfo() {
        return new ApiInfoBuilder()
                .title("Wangwei's blog")
                .description("用户接口服务")
                .contact(new Contact("Wangwei","http://www.wwang.net","wangwei.it@qq.com"))
                .version(VERSION)
                .build();
    }
}
